#include "XPT2046TouchController.hpp"
using namespace touchgfx;
#define TS_NO_IRQ_PENDING               ((uint8_t) 0)
#define TS_IRQ_PENDING                  ((uint8_t) 1)

#define TS_SWAP_NONE                    ((uint8_t) 0x01)
#define TS_SWAP_X                       ((uint8_t) 0x02)
#define TS_SWAP_Y                       ((uint8_t) 0x04)
#define TS_SWAP_XY                      ((uint8_t) 0x08)

/**
  * @}
  */

/** @defgroup etem043005xdh6_TS_Exported_Types  etem043005xdh6_TS Exported Types
  * @{
  */
/**
*  @brief TS_StateTypeDef
*  Define TS State structure
*/
typedef struct
{
  uint8_t  touchDetected;                /*!< Total number of active touches detected at last scan */
  uint16_t touchX[1];      /*!< Touch X[0], X[1] coordinates on 12 bits */
  uint16_t touchY[1];      /*!< Touch Y[0], Y[1] coordinates on 12 bits */

#if (TS_MULTI_TOUCH_SUPPORTED == 1)
  uint8_t  touchWeight[TS_MAX_NB_TOUCH]; /*!< Touch_Weight[0], Touch_Weight[1] : weight property of touches */
  uint8_t  touchEventId[TS_MAX_NB_TOUCH];     /*!< Touch_EventId[0], Touch_EventId[1] : take value of type @ref TS_TouchEventTypeDef */
  uint8_t  touchArea[TS_MAX_NB_TOUCH];   /*!< Touch_Area[0], Touch_Area[1] : touch area of each touch */
  uint32_t gestureId; /*!< type of gesture detected : take value of type @ref TS_GestureIdTypeDef */
#endif  /* TS_MULTI_TOUCH_SUPPORTED == 1 */

} TS_StateTypeDef;
void XPT2046TouchController::init()
{
  // BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
}

bool XPT2046TouchController::sampleTouch(int32_t &x, int32_t &y)
{
  TS_StateTypeDef state;
  // BSP_TS_GetState(&state);
  if (state.touchDetected)
  {
    x = state.touchY[0];
    y = state.touchX[0];

    return true;
  }
  return false;
}